<template>
	<view class="baby-top">
	
		<!-- 宝宝卡片展示 -->
		<radio-group class="block" @change="RadioChange">
		<view v-for="(item,index) in babylist" class="cu-list menu" :class="['sm-border','card-menu margin-top']" :key=index>
			<view class="cu-item">
				<view class="content">
					<image :src="item.sex=='女宝'?headico.girl:headico.boy" class="png" mode="aspectFit"></image>
					<text class="text-grey">{{item.babynike}}</text>
					<text class="cuIcon-edit text-orange" @click="editbaby(item.id)"></text>
				</view>
			</view>
			<view class="cu-item" :class="'arrow'">
				<view class="content">
					<text class="text-grey">生日：{{item.birthday}}/性别：{{item.sex}}</text>
				</view>
			</view>
			
				<view class="cu-item">
					<view class="content padding-tb-sm">设为默认</view>
					
					<radio :checked="item.ischoose==1?true:false" :value="item.id+''"></radio>
				</view>
		
		</view>
		</radio-group>
		
		<view class="cu-list menu" :class="['sm-border','card-menu margin-top']">
		<button class="bg-red margin-tb-sm lg" @click="addBaby">添加我的宝宝</button>
		</view>
		
	</view>
</template>

<script>
	import url_config from '@/common/config.js'
	export default {
		data() {
			return {
				uid:0,
				babylist:{},
				radio:'',
				headico:{
					'boy':'/static/images/milk/boy.png',
					'girl':'/static/images/milk/girl.png'
				}
			}
		},
		methods: {
		
			RadioChange(e){
				this.radio = e.detail.value
				uni.setStorageSync('bb_id',this.radio)
				uni.request({
					url:url_config.api + 'modDefault/' + this.uid + '/' + this.radio,
					success: (res) => {
						uni.showToast({
							title:'设置成功',
							duration:1000
						})
					},
					fail(e) {
						uni.showToast({
							title:'设置失败，请重试',
							duration:1000
						})
					}
				})
				
			},
			addBaby(){
				uni.navigateTo({
					url:'addbaby/addbaby?uid=' + this.uid
				})
			},
			getbabylist(){
				uni.request({
					url:url_config.api + 'getBabyList/' + this.uid,
					success: (res) => {
						//console.log(res)
						this.babylist = res.data.data
					}
				})
			},
			editbaby(bid){
				//编辑按钮
				uni.navigateTo({
					url:'addbaby/addbaby?bid=' + bid
				})
			}
		},
		onLoad() {
			this.uid = uni.getStorageSync('user_id')
			this.radio = uni.getStorageSync('bb_id')
			this.getbabylist()
			//console.log(this.uid)
		},
		onShow() {
			this.getbabylist()
		}
	}
</script>

<style>
	.baby-top{
		padding-top: 30rpx;
	}
</style>
